import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import common from '@/api/system/common'

export const constantRoutes = [

  {
    path:"/user",
    component:()=>import("@/views/table/index"),
    hidden:true,
    children:[
      {
        path:'allfile',
        name:'allfile',
        component:()=>import("@/views/table/components/AllFIle.vue"),
        hidden:true,
      },
      {
        path:'share',
        name:'share',
        component:()=>import("@/views/table/components/MyShare.vue"),
        hidden:true
      },
      {
        path:'bin',
        name:'bin',
        component:()=>import("@/views/table/components/bin.vue"),
        hidden:true
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/share',
    component: () => import('@/views/share/index.vue'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-tools'
    },
    alwaysShow: true,
    children: [
      {
        path: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: '用户管理',
          icon: 'el-icon-user-solid'
        },
      },
      {
        path: 'file',
        component: () => import('@/views/system/file/index.vue'),
        meta: {
          title: '文件管理',
          icon: 'el-icon-s-unfold'
        },
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
